package com.tyler.oshi.service;

import org.springframework.stereotype.Service;
import oshi.SystemInfo;
import oshi.hardware.CentralProcessor;
import oshi.hardware.HardwareAbstractionLayer;

/**
 * @author: TylerZhong
 * @description:
 */
@Service
public class CpuLoadMetricsService {

    // OSHI 提供的获取所有数据的入口
    SystemInfo si = new SystemInfo();

    public double[] getCpuLoad() {
        HardwareAbstractionLayer hardware = si.getHardware();
        CentralProcessor processor = hardware.getProcessor();
        // 统计1s内的使用率，所以会阻塞1s
        double[] processorCpuLoad = processor.getProcessorCpuLoad(1000);
        return processorCpuLoad;
    }
}
